package com.itboye.ihomebank.home;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.custom.FlowLayout;
import com.itboye.ihomebank.util.HuXingPopupWindow;
import com.itboye.ihomebank.util.QiZuPopupWindow;
import com.itboye.ihomebank.util.ZuQiPopupWindow;
import com.itboye.ihomebank.wheelview.OnWheelScrollListener;
import com.itboye.ihomebank.wheelview.WheelView;
import com.itboye.ihomebank.wheelview.adapter.NumericWheelAdapter;

/**
 * 合同1
 * 
 */
public class ActivityTianXieHeTongOne extends BaseOtherActivity {

	private Button yulan, next;
	private FlowLayout flowLayout;
	private RelativeLayout re_zuqi, re_huxing,re_qizu;
	TextView add_lift_tv;

	/** 租期弹出框 */
	private ZuQiPopupWindow popupWindow;
	/** 户型弹出框 */
	private HuXingPopupWindow huxingWindow;
	/** 起租日期弹出框 */
	private QiZuPopupWindow qizuWindow;
	// 租期
	private WheelView year;
	// 户型
	private WheelView huxing_01, huxing_02, huxing_03;
	// 起租日期
	private WheelView qizu_01, qizu_02, qizu_03;
	// 显示（租期，户型，起租日期）
	TextView edit_chu_name2, edit_chu_zhengjianum,edit_chephone;
	
	RelativeLayout re_wuye,re_shangwang,re_weisheng,re_dianqi,re_shuifei,re_ranqi;
	//物业等选项的图片
	ImageView img_wuye,img_shangwang,img_weisheng,img_dianqi,img_shuifei,img_ranqi;
	//物业等选项的文字
	TextView txt_wuye,txt_shangwang,txt_weisheng,txt_dianqi,txt_shuifei,txt_ranqi;
	
	/** 点击标签的次数 */
	private int dian = 0;
	
	@SuppressLint("ResourceAsColor") @Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.yulan:
			// intent=new Intent(this,.class);
			// startActivity(intent);
			break;
		case R.id.next:
			intent = new Intent(this, ActivityEditFangZuXinXi.class);
			startActivity(intent);
			break;
		case R.id.re_zuqi:// 租期
			popupWindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.re_huxing:// 户型
			huxingWindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.re_qizu:// 起租日期
			qizuWindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.img_wuye:
			dian++;
			if(dian%2!=0){
				img_wuye.setBackgroundResource(R.drawable.wuyefei_selected);
				txt_wuye.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_wuye.setBackgroundResource(R.drawable.wuyefei);
				txt_wuye.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
		case R.id.img_shangwang:
			dian++;
			if(dian%2!=0){
				img_shangwang.setBackgroundResource(R.drawable.wifi_selected);
				txt_shangwang.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_shangwang.setBackgroundResource(R.drawable.wifi);
				txt_shangwang.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
		case R.id.img_weisheng:
			dian++;
			if(dian%2!=0){
				img_weisheng.setBackgroundResource(R.drawable.weishengfei_selected);
				txt_weisheng.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_weisheng.setBackgroundResource(R.drawable.weishengfei);
				txt_weisheng.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
		case R.id.img_dianqi:
			dian++;
			if(dian%2!=0){
				img_dianqi.setBackgroundResource(R.drawable.dianfei_selected);
				txt_dianqi.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_dianqi.setBackgroundResource(R.drawable.dianqifei);
				txt_dianqi.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
		case R.id.img_shuifei:
			dian++;
			if(dian%2!=0){
				img_shuifei.setBackgroundResource(R.drawable.shuifei_selected);
				txt_shuifei.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_shuifei.setBackgroundResource(R.drawable.shuifei);
				txt_shuifei.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
		case R.id.img_ranqi:
			dian++;
			if(dian%2!=0){
				img_ranqi.setBackgroundResource(R.drawable.ranqifei_selected);
				txt_ranqi.setTextColor(this.getResources().getColor(R.color.blue));
			}else{
				img_ranqi.setBackgroundResource(R.drawable.ranqifei);
				txt_ranqi.setTextColor(this.getResources().getColor(R.color.gray));
			}
			break;
			
		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		return R.layout.activity_tianxiehetong_one;
	}

	@Override
	protected void onInitController() {

	}

	@Override
	protected void onInit() {
		// 租期
		popupWindow = new ZuQiPopupWindow(this, zuqiListener);
		year = (WheelView) popupWindow.getContentView().findViewById(
				R.id.zuqi_year);
		year.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter numericWheelAdapter1 = new NumericWheelAdapter(
				MyApplcation.ctx, 1, 12);
		numericWheelAdapter1.setLabel("个月");
		year.setViewAdapter(numericWheelAdapter1);
		year.setCyclic(true);// 是否可循环滑动
		year.addScrollingListener(scrollListener);

		// 户型
		huxingWindow = new HuXingPopupWindow(this, huxingListener);
		huxing_01 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_01);
		huxing_01.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume02 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 4);
		nume02.setLabel("室");
		huxing_01.setViewAdapter(nume02);
		huxing_01.setCyclic(true);// 是否可循环滑动
		huxing_01.addScrollingListener(scrollListener);

		huxing_02 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_02);
		huxing_02.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume03 = new NumericWheelAdapter(MyApplcation.ctx,
				0, 3);
		nume03.setLabel("厅");
		huxing_02.setViewAdapter(nume03);
		huxing_02.setCyclic(true);// 是否可循环滑动
		huxing_02.addScrollingListener(scrollListener);

		huxing_03 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_03);
		huxing_03.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume04 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 2);
		nume04.setLabel("卫");
		huxing_03.setViewAdapter(nume04);
		huxing_03.setCyclic(true);// 是否可循环滑动
		huxing_03.addScrollingListener(scrollListener);
		
		
		//起租日期
		qizuWindow=new QiZuPopupWindow(this, qizuListener);
		qizu_01 = (WheelView) qizuWindow.getContentView().findViewById(
				R.id.qizu_01);
		qizu_01.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume12 = new NumericWheelAdapter(MyApplcation.ctx,
				2014,2018);
		nume12.setLabel("年");
		qizu_01.setViewAdapter(nume12);
		qizu_01.setCyclic(true);// 是否可循环滑动
		qizu_01.addScrollingListener(scrollListener);

		qizu_02 = (WheelView) qizuWindow.getContentView().findViewById(
				R.id.qizu_02);
		qizu_02.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume13 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 12);
		nume13.setLabel("月");
		qizu_02.setViewAdapter(nume13);
		qizu_02.setCyclic(true);// 是否可循环滑动
		qizu_02.addScrollingListener(scrollListener);

		qizu_03 = (WheelView) qizuWindow.getContentView().findViewById(
				R.id.qizu_03);
		qizu_03.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume14 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 31);
		nume14.setLabel("日");
		qizu_03.setViewAdapter(nume14);
		qizu_03.setCyclic(true);// 是否可循环滑动
		qizu_03.addScrollingListener(scrollListener);

	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		add_lift_tv.setText("合同填写(1/4)");

	}
	/**
	 * 租期
	 */
	OnClickListener zuqiListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.zuqi_cancel:
				popupWindow.dismiss();
				break;
			case R.id.zuqi_ok:// 完成
				popupWindow.dismiss();
				edit_chu_name2.setText(year.getCurrentItem() + 1 + "个月");
				break;
			default:
				break;
			}
		}
	};
	/**
	 * 户型
	 */
	OnClickListener huxingListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.huxing_cancel:
				huxingWindow.dismiss();
				break;
			case R.id.huxing_ok:// 完成
				huxingWindow.dismiss();
				edit_chu_zhengjianum.setText(huxing_01.getCurrentItem() + 1
						+ "室" +(huxing_02.getCurrentItem()+0) + "厅"
						+ (huxing_03.getCurrentItem() + 1) + "卫");
				break;

			default:
				break;
			}

		}

	};
	/**
	 * 起租日期
	 */
	OnClickListener qizuListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.qizu_cancel:
				qizuWindow.dismiss();
				break;
			case R.id.qizu_ok:// 完成
				qizuWindow.dismiss();
				edit_chephone.setText(qizu_01.getCurrentItem() + 2014
						+ "年" + (qizu_02.getCurrentItem()+1) + "月"
						+ (qizu_03.getCurrentItem() + 1) + "日");
				break;

			default:
				break;
			}

		}

	};
	OnWheelScrollListener scrollListener = new OnWheelScrollListener() {
		@Override
		public void onScrollingStarted(WheelView wheel) {

		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			// int n_year = year.getCurrentItem() + 1950;//年
			// int n_month = month.getCurrentItem() + 1;//月
			//
			// initDay(n_year,n_month);
			//
			// String birthday=new
			// StringBuilder().append((year.getCurrentItem()+1950)).append("-").append((month.getCurrentItem()
			// + 1) < 10 ? "0" + (month.getCurrentItem() + 1) :
			// (month.getCurrentItem() +
			// 1)).append("-").append(((day.getCurrentItem()+1) < 10) ? "0" +
			// (day.getCurrentItem()+1) : (day.getCurrentItem()+1)).toString();
			// tv1.setText("年龄             "+calculateDatePoor(birthday)+"岁");
			// tv2.setText("星座             "+getAstro(month.getCurrentItem() +
			// 1,day.getCurrentItem()+1));
		}
	};
}
